# -*- coding: utf-8 -*-
"""
# @Time    : 2021/1/6 下午5:05
# @Author  : tgy
"""

import time
from functools import wraps



def timer(fun):
    """
    上面的 timer 有且只能有一个参数，用来接收@timer修饰的函数变量，
    下面的 inner 接收 @timer修饰的函数重新赋值的参数，并把参数赋值给timer传递过来的函数
    """
    def inner(*args, **kwargs):
        start = time.time()
        result = fun(*args, **kwargs)
        consume = time.time() - start
        print(f'耗时:{consume}')
        return result

    return inner


@timer  # test01 = timer(test01)
def test01():
    ...
    time.sleep(3)

mapping = dict()


def requestMapping(path,method = 'GET'):
    def outter(handler):

        # 使用 @wraps把 handler函数的属性赋值给 inner
        @wraps(handler)
        def inner(*args, **kwargs):
            result = handler(*args, **kwargs)
            return result

        mapping[path] = {"call": handler, "method": method}
        return inner
    return outter


@requestMapping(path="/login", method='POST')
def login(username,password):
    ...
    print(username,password)


if __name__ == '__main__':
    ...
    # mapping['/login']['call']("123","1212")
    print(login)